package com.springbootblog.dao.sqlBuilder;

import com.springbootblog.pojo.ChatRecord;

import java.util.Map;

public class ChatSqlBuilder
{
    public String updateChatRecordStatus(Map<String, Object> param)
    {
        String sql = "UPDATE chat_record SET is_read = 1 WHERE to_user_id = '"+param.get("param1")+"' AND from_user_id = '"+param.get("param2")+"' AND is_read = 0 ";
        return sql;
    }

    public String getChatRecordList(Map<String, Object> param)
    {
        String sql = "SELECT *,content AS msg FROM chat_record " +
                "        WHERE (from_user_id = '"+param.get("from_user_id")+"' AND to_user_id = '"+param.get("to_user_id")+"') " +
                "        OR (to_user_id = '"+param.get("from_user_id")+"' AND from_user_id = '"+param.get("to_user_id")+"') " +
                "        ORDER BY addtime ASC";
        return sql;
    }

    public String addChatRecord(ChatRecord chatRecord)
    {
        String sql = "INSERT INTO chat_record (from_user_id,to_user_id,addtime,content) VALUES ('"+chatRecord.getFrom_user_id()+"','"+chatRecord.getTo_user_id()+"',NOW(),'"+chatRecord.getMsg()+"')";
        return sql;
    }

    public String getUnReadNumber(Map<String, Object> param)
    {
        String sql = "SELECT COUNT(id) AS number FROM chat_record WHERE to_user_id = '"+param.get("to_user_id")+"' AND from_user_id = '"+param.get("user_id")+"' AND is_read = 0 ";
        // System.out.println(sql);
        return sql;
    }

}
